package com.vinhvt.effiport.financial.ep;

import java.util.ArrayList;
import java.util.List;

import com.vinhvt.effiport.util.Helper;

public class Underlying {
	private String symbol = "";
	private List<Transaction> transactions = new ArrayList<Transaction>();
	private List<Double> listRateOfReturn = new ArrayList<Double>();
	
	public Underlying(String symbol) {
		setSymbol(symbol);
	}
			
	public Underlying(String symbol, List<Transaction> transactions, int mode) {
		setSymbol(symbol);
		setTransactions(transactions, mode);
		listRateOfReturn = this.loadRateOfReturnList();
	}
	
	private List<Double> loadRateOfReturnList() {
		List<Double> ror = new ArrayList<Double>();
		List<Transaction> trans = this.getTransactions();
		ror.add(0, 0.0); // default

		int times = trans.size();
		for (int i = 1; i < times; i++) {
			Transaction t0 = trans.get(i - 1);
			Transaction t1 = trans.get(i);
			Double tmp = (t1.getClosedPrice() - t0.getClosedPrice())
					/ t0.getClosedPrice() * 100;
			ror.add(Helper.round(tmp));
		}

		return ror;
	}

	public Underlying(String symbol, List<Double> aRateOfReturnList) {
		setSymbol(symbol);
		setRateOfReturnList(aRateOfReturnList);
	}
	
	public void setSymbol(String symbol) {
		this.symbol = symbol;
	}

	public String getSymbol() {
		return symbol;
	}

	public void setTransactions(List<Transaction> transactions, int mode) {
		transactions = Helper.refillTransactionInMode(transactions, mode);
		this.transactions = transactions;
	}

	public List<Transaction> getTransactions() {
		return transactions;
	}

	public void setRateOfReturnList(List<Double> aRateOfReturnList) {
		this.listRateOfReturn = aRateOfReturnList;
	}

	public List<Double> getRateOfReturnList() {
		return listRateOfReturn;
	}	
}
